﻿using UnityEditor;
using UnityEngine;

namespace GameToolkit.Editor
{
    [CustomEditor(typeof(RuntimeNavMeshBuilder))]
	public class RuntimeNavMeshBuildierEditor : VolumeBoundsEditor
    {
        bool showOthers;

        protected override void OnEnable()
        {
            showOthers = false;
            base.OnEnable();
#if !UNITY_2022_3_OR_NEWER
            UnityEditor.AI.NavMeshVisualizationSettings.showNavigation++;
#endif
        }

        protected override void OnDisable()
        {
            base.OnDisable();
#if !UNITY_2022_3_OR_NEWER
            UnityEditor.AI.NavMeshVisualizationSettings.showNavigation--;
#endif
        }

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            var other = QuickGUI.DrawHeader("Other Builders", "RTNavBuilders", false);
            showOthers = other;
            if (other)
            {
                QuickGUI.BeginContents(10);
                var iter = RuntimeNavMeshBuilder.GetBuildersEnumerator();
                while (iter.MoveNext())
                {
                    var builder = iter.Current;
                    if (builder == target || builder == null)
                        continue;
                    if (GUILayout.Button(builder.name, "helpbox"))
                    {
                        Selection.activeGameObject = builder.gameObject;
                    }
                }
                QuickGUI.EndContents();
            }
        }
    }
}